package interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerExceptionResolverComposite;

import service.v2.MessageService;



public class ExtHandlerExceptionResolverComposite extends HandlerExceptionResolverComposite{
	
	@Autowired
	private MessageService messageService;
	
	@Override
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {
		if(ex != null){
			request.setAttribute("message", ex.getMessage());
			request.setAttribute("error_url", request.getRequestURL());
			request.setAttribute("member_id", request.getHeader("SECRET")==null?"0":request.getHeader("SECRET"));
			messageService.saveErrorMsg(ex.getMessage(),String.valueOf(request.getRequestURL()),request.getHeader("SECRET")==null?"0":request.getHeader("SECRET"));
		}
		return super.resolveException(request, response, handler, ex);
	}
}
